/**
 * Created by Administrator on 2017/1/16.
 */

var MJPlayer = require('../MJ/player').MJPlayer;
var MJ = require('../MJ/MJ');
var Const = require('./const');
var SubCode = require('../subCode');

exports.TTMJPlayer = MJPlayer.extend({

    //-------------------------------------------------------------------------
    _SHAIPAI: function(){
        //---------------------------------------------------------------------
        this._isBai = false;                              // 是否摆牌
        this._huCards = [];                               // 胡的牌
        this._baiCards = [];                              // 摆的牌
        this._useableGang = [];                           // 能杠的牌

        //---------------------------------------------------------------------

        this.setBaiPai = function(bai) { this._isBai = bai };
        this.isBaiPai = function() { return this._isBai; };

        this.setHuCards = function(cards) { this._huCards = cards; };
        this.getHuCards = function(){ return this._huCards; };

        this.setBaiCards = function(cards) { this._baiCards = cards; };
        this.getBaiCards = function(){ return this._baiCards; };

        this.reset = function() {
            this._isBai = false;
            this._huCards = [];
            this._baiCards = [];
            this._useableGang = [];
        };

        this.containsHuCard = function(card) {
            return this._huCards.indexOf(card) != -1;
        };

        this.setUsableGang = function(useableGang) {
            useableGang = useableGang || [];
            useableGang.forEach(function(gang){
                this._useableGang.push(+gang);
            }.bind(this));
        };
        this.getUsableGang = function() {
            return this._useableGang;
        };
        this.containsUsableGang = function(gangCard) {
            return this._useableGang.indexOf(gangCard) != -1;
        };
        this.isCardBai = function(card) {
            return this._baiCards.indexOf(card) != -1;
        };
    },

    //-------------------------------------------------------------------------
    _shaiPai: null,             // 晒牌
    _guoShuiFan: 0,             // 过水胡的番数

    //-------------------------------------------------------------------------
    getShaiPai: function() {
        return this._shaiPai;
    },

    setShaiState: function(stats) {
        this._stat.shaiStat = stats;
    },

    // 重置过水胡状态
    resetGuoShuiFan: function() {
        this._guoShuiFan = -1;
    },

    //-------------------------------------------------------------------------


    init: function(uid, msg) {
        this._super(uid, msg);

        this._stat.roundFan = 0;            // 本轮番数

        this._stat.zmCount = 0;             // 自摸次数
        this._stat.dpCount = 0;             // 点炮次数
        this._stat.dhCount = 0;             // 点胡次数
        this._stat.anGangCount = 0;        // 暗杠次数
        this._stat.mingGangCount = 0;      // 明杠次数

        this._stat.shaiStat = {};           // 胡牌时输我方玩家玩家的摆牌状态

        this._shaiPai = new this._SHAIPAI();    // 晒牌

        this._guoShuiFan = -1;
    },

    settlementGangScore: function() {
        var room = this.getRoom();

        // var notHuCount = room.getMaxPlayer() - room.getHuPlayerCount();
        //
        // if (!this.isRoundTing() && (notHuCount > 1)) {
        //     return;
        // }

        var dealer = room.getDealerPlayer();

        for (var i = 0, l = this._gangCards.length; i < l; ++i) {
            var gangInfo = this._gangCards[i];
            var player = this;

            if (gangInfo.overdue || gangInfo.unscored) {
                continue;
            }

            // 底分
            var baseScore = room.getOption("BASESCORE") || 1;
            var score = Const.GangScore[gangInfo.gang] || 0;

            // 计算杠上杠
            if (gangInfo.prevGang) {
                var deep = 0;
                var a = gangInfo;
                while (a.prevGang) {
                    ++deep;
                    a = gangInfo.prevGang;
                }
                score *= Math.floor(Math.pow(2, deep));
            }

            logger.debug("计算杠分：" + JSON.stringify(gangInfo) + " => " + score);

            score *= baseScore;

            gangInfo.targets.forEach(function(targetIndex) {
                var targetPlayer = room.getPlayerByIndex(targetIndex);
                if (targetPlayer) {
                    player.addRoundGangScore(score);
                    targetPlayer.addRoundGangScore(-score);
                }
            });
        }
    },

    __calcScore: function(targetIndex) {
        var room = this.getRoom();
        var roundItemScores = clone(this._stat.roundItemScores);

        //---------------------------------------------------------------------
        // 删除对于当前玩家多余的番数
        var delKeys = [];
        ExObject.each(roundItemScores, function(key, value){
            key = +key;

            if ((key >= Const.ScoreRule.TARGET_SHAIPAI)
                && (key <= (Const.ScoreRule.TARGET_SHAIPAI + 4))
                && (key != (Const.ScoreRule.TARGET_SHAIPAI + targetIndex))) {
                delKeys.push(key);
            }
        });
        delKeys.forEach(function(key){
            delete roundItemScores[key];
        });
        //---------------------------------------------------------------------

        var basicFan = this._stat.roundPatternScore + ExObject.sumValue(roundItemScores);
        // if (this._shaiPai.isBaiPai()) {
        //     if (basicFan == 0) {
        //         basicFan = 1;
        //     } else {
        //         basicFan += 1;  // 晒牌后胡牌按照两倍计算
        //     }
        //
        //     if (this._stat.shaiStat.hasOwnProperty(targetIndex)) {
        //         basicFan += 1;  // 他放晒牌再按照两倍计算
        //     }
        // }

        var maxFan = room.getOption("FAN");
        this._stat.roundFan = Math.min(maxFan, basicFan);

        var baseScore = room.getOption("BASESCORE") || 1;    // 底分
        var score = Math.pow(2, this._stat.roundFan);
        score *= baseScore;

        return score;
    },

    settlementPatternScore: function() {
        if (!this.isRoundHu()) {
            return;
        }

        var player = this;
        var room = this.getRoom();
        var dealer = room.getDealerPlayer();

        // 自摸加番
        // var zms = room.getOption("ZMS");
        // var isZM = (this.getRoundResult() == MJ.Result.ZM);
        // if (isZM && zms == 2) {
        //     this.addRoundItemScores(Const.ScoreRule.ZM, 1);
        // }

        // var basicFan = this._stat.roundPatternScore + ExObject.sumValue(this._stat.roundItemScores);
        // if (this._shaiPai.isBaiPai()) {
        //     basicFan *= 2;  // 晒牌后胡牌按照两倍计算
        // }
        //
        // var maxFan = room.getOption("FAN");
        // this._stat.roundFan = Math.min(maxFan, basicFan);
        //
        // var baseScore = room.getOption("BASESCORE") || 1;    // 底分
        // var score = Math.pow(2, this._stat.roundFan);
        // score *= baseScore;

        // 自摸加底
        //if (isZM && zms == 1) {
        //    score += 1;
        //}

        // var transPlayer = null;
        // if (this.existRoundScoreRule(Const.ScoreRule.GSH) && room.getOption("DGH") == 1) {
        //     var gangIndex = this._gangCards.length - 1;
        //     if (gangIndex >= 0) {
        //         var gangInfo = this._gangCards[gangIndex];
        //         if (gangInfo.gang == MJ.Gang.DIAN) {
        //             transPlayer = room.getPlayerByIndex(gangInfo.from);
        //         }
        //     }
        // }

        // 结算牌型及基础分
        // if (transPlayer) {
        //     var playerNum = this._stat.roundTarget.length;
        //     var allScore = score*playerNum;
        //     transPlayer.addRoundScore(-allScore);
        //     player.addRoundScore(allScore);
        // } else {
            this._stat.roundTarget.forEach(function(playerIndex) {
                var target = room.getPlayerByIndex(playerIndex);
                if (target) {
                    var score = this.__calcScore(playerIndex);

                    target.addRoundScore(-score);
                    player.addRoundScore(score);
                }
            }.bind(this));
        //}
    },

    settlementTingScore: function() {
        var player = this;
        var room = this.getRoom();

        if (player.isRoundTing()) {
            return;
        }

        var baseScore = room.getOption("BASESCORE") || 1;    // 底分
        var maxFan = room.getOption("FAN");

        room.enumPlayers(function(eIndex, ePlayer) {
            if ((player.getIndex() != eIndex) && ePlayer.isRoundTing() && !ePlayer.isRoundHu()) {
                var basicFan = Const.PatternScore[ePlayer.getRoundPattern()] || 0;
                basicFan += ExObject.sumValue(ePlayer._stat.roundItemScores);

                var score = Math.pow(2, Math.min(maxFan, basicFan));
                score *= baseScore;

                player.addRoundScore(-score);
                ePlayer.addRoundScore(score);
            }
        });
    },

    /**
     * 判断是否是小胡
     * @param huCard
     * @param result
     */
    isXH: function(huCard) {
        var room = this.getRoom();

        var cards = clone(this._handCards.getCards());
        ExObject.addNumber(cards, huCard, 1);

        var gangFan = this._calcGangFan(cards, huCard);
        if (gangFan > 0) {
            return false;
        }

        var cardCount = MJ.sumCardsNum(cards);
        if (cardCount <= 2) {
            return false;
        }

        if (room.getPublicCards().getRemainNum() == 0) {
            return false;
        }

        if (room.getHideOption("JXW")) {
            if (this._checkJXW(cards, huCard)) {
                return false;
            }
        }

        return true;
    },

    /**
     * 判断胡牌规则
     */
    settlementRules: function() {
        var room = this.getRoom();
        var player = this;

        if (!this.isRoundHu()) {
            return;
        }

        var huCard = this.getRoundHuCard();
        var cards = this.getRoundHuCards();
        var pattern = this.getRoundPattern();

        // 七对不计算杠番
        if (pattern != Const.Pattern.PAIR7 &&
            pattern != Const.Pattern.PAIR7_LONG &&
            pattern != Const.Pattern.PAIR7_COLOR &&
            pattern != Const.Pattern.PAIR7_COLOR_LONG &&
            pattern != Const.Pattern.JiangDui7) {
            var gangFan = this._calcGangFan(cards, huCard);
            if (gangFan > 0) {
                this.addRoundItemScores(Const.ScoreRule.GANG, gangFan);
            }
        }

        var cardCount = MJ.sumCardsNum(cards);
        if (cardCount <= 2) {
            var rule = Const.ScoreRule.SINGLE;
            this.setRoundScoreRule(rule);
            this.addRoundItemScores(rule, Const.ItemScore[rule]);
        }

        if (room.getPublicCards().getRemainNum() == 0) {
            if (this.getRoundResult() == MJ.Result.DH) {
                var rule = Const.ScoreRule.HaiDiHu;
                this.setRoundScoreRule(rule);
                this.addRoundItemScores(rule, Const.ItemScore[rule]);
            } else {
                if (this.existRoundScoreRule(Const.ScoreRule.GSH)) {
                    this.unsetRoundScoreRule(Const.ScoreRule.GSH);
                    var rule = Const.ScoreRule.HaiDiHua;
                    this.setRoundScoreRule(rule);
                    this.addRoundItemScores(rule, Const.ItemScore[rule]);
                } else {
                    var rule = Const.ScoreRule.SaoDiHu;
                    this.setRoundScoreRule(rule);
                    this.addRoundItemScores(rule, Const.ItemScore[rule]);
                }
            }
        }

        if (room.getHideOption("JXW")) {
            if (this._checkJXW(cards, huCard)) {
                var rule = Const.ScoreRule.JiaXinWu;
                this.setRoundScoreRule(rule);
                this.addRoundItemScores(rule, Const.ItemScore[rule]);
            }
        }
    },

    /**
     * 判断胡牌规则
     */
    settlementTingRules: function(pattern, huCard) {
        var room = this.getRoom();
        var player = this;
        var rules = {};

        var cards = clone(this.getHandCards());
        ExObject.addNumber(cards, huCard, 1);

        // 七对不计算杠番
        if (pattern != Const.Pattern.PAIR7 &&
            pattern != Const.Pattern.PAIR7_LONG &&
            pattern != Const.Pattern.PAIR7_COLOR &&
            pattern != Const.Pattern.PAIR7_COLOR_LONG &&
            pattern != Const.Pattern.JiangDui7) {
            var gangFan = this._calcGangFan(cards, huCard);
            if (gangFan > 0) {
                rules[Const.ScoreRule.GANG] = gangFan;
            }
        }

        var cardCount = MJ.sumCardsNum(cards);
        if (cardCount <= 2) {
            var rule = Const.ScoreRule.SINGLE;
            rules[rule] = Const.ItemScore[rule];
        }

        if (room.getHideOption("JXW")) {
            if (this._checkJXW(cards, huCard)) {
                var rule = Const.ScoreRule.JiaXinWu;
                rules[rule] = Const.ItemScore[rule];
            }
        }

        return rules;
    },

    /**
     * 判断一条龙
     * @private
     */
    _checkYTL: function(cards) {
        var isYTL = false;

        var colors = this.getRoom().getSubConfig().colors;
        colors.forEach(function(color) {
            if (this._checkColorYTL(color, MJ.getColorCards(cards, color))) {
                isYTL = true;
            }
        }.bind(this));

        return isYTL;
    },

    _checkColorYTL: function(color, colorCards) {
        if (ExObject.count(colorCards) != 9) {
            return false;
        }

        var isYTL = false;
        var colorMinCard = MJ.getValue(color, 1);
        var colorMaxCard = MJ.getValue(color, MJ.COLOR_CARD_NUM);
        var colorSplits = MJ.splitColorCards(colorMinCard, colorMaxCard, colorCards);
        colorSplits.forEach(function(items) {
            var itemCards = {};
            items.forEach(function(item) {
                if (item.length == 3) {
                    if (item[0] != item[1]) { //不是三张一样的牌
                        itemCards[item[0]] = 1;
                        itemCards[item[1]] = 1;
                        itemCards[item[2]] = 1;
                    }
                }
            });

            if (ExObject.count(itemCards) == 9) {
                isYTL = true;
            }
        });

        return isYTL;
    },

    /**
     * 判断夹心五
     * @param cards
     * @param huCard
     * @private
     */
    _checkJXW: function(cards, huCard) {
        var huPoint = MJ.getPoint(huCard);
        if (huPoint != 5) {
            return false;
        }

        var isJiaXinWu = false;
        var huColor = MJ.getColor(huCard);
        var huColorCards = MJ.getColorCards(cards, huColor);
        var huColorMinCard = MJ.getValue(huColor, 1);
        var huColorMaxCard = MJ.getValue(huColor, MJ.COLOR_CARD_NUM);

        var colorSplits = MJ.splitColorCards(huColorMinCard, huColorMaxCard, huColorCards);
        colorSplits.forEach(function(items) {
            items.forEach(function(item) {
                if (isJiaXinWu) {
                    return;
                }

                /*if (item.length == 2) {
                    if (item[0] == huCard) {
                        isJiaXinWu = true;
                    }
                } else */if (item.length == 3) {
                    if (item[0] != item[1]) { //不是三张一样的牌
                        if (huCard == item[1]) { //夹张
                            isJiaXinWu = true;
                        }
                    }
                }
            });
        });

        return isJiaXinWu;
    },

    setTingRules: function(rules) {
        if (!rules) {
            return;
        }

        var player = this;
        ExObject.eachKeyNum(rules, function(rule, value) {
            player.setRoundScoreRule(rule);
            player.addRoundItemScores(rule, value);
        });
    },

    _calcGangFan: function(cards, huCard) {
        var gangFan = this._gangCards.length;

        this._pengCards.forEach(function(card) {
            if (cards[card]) {
                gangFan++;
            }
        });

        gangFan += ExObject.countEQ(cards, 4);

        return 0;//gangFan;
    },

    settlement: function() {
        this._super();

        this.addRoundScore(this._stat.roundGangScore);

        if (this._stat.roundResult == MJ.Result.ZM) {
            this._stat.zmCount++;
        } else if (this._stat.roundResult == MJ.Result.DH) {
            this._stat.dhCount++;
            if (this._stat.roundTarget.length > 0) {
                var dpPlayer = this.getRoom().getPlayerByIndex(this._stat.roundTarget[0]);
                if (dpPlayer) {
                    dpPlayer._stat.dpCount++;
                }
            }
        }

        for (var i = 0, l = this._gangCards.length; i < l; ++i) {
            var gangInfo = this._gangCards[i];
            if (gangInfo.gang == MJ.Gang.AN || gangInfo.gang == MJ.Gang.ANS) {
                this._stat.anGangCount++;
            } else {
                this._stat.mingGangCount++;
            }
        }
    },

    /******************************************************************
     * 重载的接口
     ******************************************************************/

    checkPengWithCard: function(card) {
        if (!this._super(card)) {
            return false;
        }

        if (this._shaiPai.isBaiPai()) {
            // 摆牌后不能碰牌
            return false;
        }

        // 检查碰牌后手牌是不是换只剩下别人的胡牌
        var self = this;
        var room = this.getRoom();
        var canPeng = false;
        ExObject.each(this._handCards.getCards(), function(eCard, eCardNum){
            eCard = +eCard; eCardNum = +eCardNum;
            if (eCardNum > 0 && eCard != card) {
                if (!room.isCardIsOtherBaiHu(self.getIndex(), eCard)) {
                    canPeng = true;
                    return false;
                }
            }
        });
        return canPeng;
    },

    checkGangWithCard: function(card) {
        if (this._super(card)) {
            // 摆牌后可以吃杠
            if (this._shaiPai.isBaiPai()) {
                if (!this._shaiPai.isCardBai(card)) {
                    var canGang = this._shaiPai.containsUsableGang(card);
                    logger.debug("checkGangWithCard: " + card + ", " + canGang + " => " + JSON.stringify(this._shaiPai.getUsableGang()));
                    return canGang;
                }
            } else {
                return true;
            }
        }
        return false;
    },

    checkGang: function() {
        var self = this;

        var gangArray = this._super();

        var filterGangArray = [];
        if (!self._shaiPai.isBaiPai()) {
            gangArray.forEach(function(gangItem){
                switch (gangItem.gang) {
                    case MJ.Gang.BA:
                        var gangCard = gangItem.card;
                        var room = self.getRoom();
                        var canGang = !room.isCardIsOtherBaiHu(self.getIndex(), gangCard);
                        if (canGang) {
                            filterGangArray.push(gangItem);
                        }
                        logger.debug("checkGang.BA: " + gangCard + ", " + canGang);
                        break;
                    default:
                        filterGangArray.push(gangItem);
                }
            });
            return filterGangArray;
        }

        gangArray.forEach(function(gangItem){
            // 摆牌后只能吃杠和巴杠
            switch (gangItem.gang) {
                case MJ.Gang.BA:
                    var gangCard = gangItem.card;
                    if (self._shaiPai.containsUsableGang(gangCard)) {
                        var canGang = true;
                        var room = self.getRoom();
                        canGang = !room.isCardIsOtherBaiHu(self.getIndex(), gangCard);
                        if (canGang) {
                            filterGangArray.push(gangItem);
                        }
                    }
                    logger.debug("checkGang.BA: " + gangCard + ", " + canGang + " => " + JSON.stringify(self._shaiPai.getUsableGang()));
                    break;
                case MJ.Gang.DIAN:
                    var gangCard = gangItem.card;
                    if (!self._shaiPai.isCardBai(gangCard)) {    // 杠的牌在晒牌里面，不能杠
                        if (self._shaiPai.containsUsableGang(gangCard)) {
                            filterGangArray.push(gangItem);
                        }
                        logger.debug("checkGang.DIAN: " + gangCard + ", " + self._shaiPai.containsUsableGang(gangCard) + " => " + JSON.stringify(self._shaiPai.getUsableGang()));
                    }
                    break;
                default:
                    var gangCard = gangItem.card;
                    if (self._shaiPai.containsUsableGang(gangCard)) {
                        filterGangArray.push(gangItem);
                    }
                    logger.debug("checkGang: " + gangCard + ", " + self._shaiPai.containsUsableGang(gangCard) + " => " + JSON.stringify(self._shaiPai.getUsableGang()));
                    break;
            }
        });
        return filterGangArray;
    },

    getReconnectInfo: function(isSelf) {
        var info = this._super(isSelf);
        info.shaiPai = {
            isBai: this._shaiPai.isBaiPai(),
            huCards: this._shaiPai.getHuCards(),
            baiCards: this._shaiPai.getBaiCards()
        };
        return info;
    },

    getSettlementInfo: function() {
        var info = this._super();
        info.gangCards = this._gangCards;
        info.pengCards = this._pengCards;
        info.handCards = this._handCards.getCards();
        info.shaiPai = {
            isBai: this._shaiPai.isBaiPai(),
            huCards: this._shaiPai.getHuCards(),
            baiCards: this._shaiPai.getBaiCards()
        };
        return info;
    },

    onStartNewRound: function() {
        this._super();
        this._stat.roundFan = 0;
        this._stat.shaiStat = {};

        this._shaiPai.reset();

        this._guoShuiFan = -1;
    },

    checkHuWithCard: function(card) {
        var pattern = this._super(card);
        if (this._guoShuiFan == -1) {
            return pattern;
        }

        // 处理过水胡
        var patternScore = Const.PatternScore[pattern];
        if (patternScore > this._guoShuiFan) {  // 只有番数变大才能胡牌
            return pattern;
        }
        return Const.Pattern.NONE;
    },

    checkHuLogic: function(cards, huCard) {
        var pattern = this._super(cards, huCard);
        if (pattern == MJ.Pattern.NONE) {
            return pattern;
        }

        // if ((this.getGangCount() == 4) && (ExObject.sumValue(cards) == 1)) {   // 十八学四
        //     return Const.Pattern.ShiBaXueSi;
        // }

        if (pattern == MJ.Pattern.SINGLE) {
            pattern = MJ.Pattern.PAIR;
        }

        var colors = this.getColorsWithCards(cards);

        // var exPattern = 0;
        // if (colors.length == 1) { // 清一色
        //     exPattern = 5;
        // }
        //
        // if (pattern == MJ.Pattern.PAIR7) {
        //     if (ExObject.countEQ(cards, 4) > 0) {
        //         exPattern += 2;
        //     }
        // }
        //
        // if (exPattern) {
        //     pattern = pattern*10 + exPattern;
        // }

        if (pattern == MJ.Pattern.PAIR7) {
            var num4Cards = ExObject.countEQ(cards, 4);
            if (num4Cards == 0) {
                if (colors.length == 1) {
                    pattern = Const.Pattern.PAIR7_COLOR;    // 清七对
                }
            } else if (num4Cards == 1) {
                if (colors.length == 1) {
                    pattern = Const.Pattern.PAIR7_COLOR_LONG;    // 清龙七对
                } else {
                    pattern = Const.Pattern.PAIR7_LONG;         // 龙七对
                }
            } else {
                if (colors.length == 1) {
                    pattern = Const.Pattern.PAIR7_COLOR_LONG2;    // 清双龙七对
                } else {
                    pattern = Const.Pattern.PAIR7_LONG2;         // 双龙七对
                }
            }
        } else if (colors.length == 1) {
            if (pattern == Const.Pattern.PAIR) {
                // 清对
                pattern = Const.Pattern.PAIR_COLOR;
            } else {
                // 清一色
                pattern = Const.Pattern.NORMAL_COLOR;
            }
        }

        var room = this.getRoom();

        if (room.getHideOption("YJJD")) {
            if (pattern == Const.Pattern.NORMAL || pattern == Const.Pattern.NORMAL_COLOR) {
                var hu19 = true;
                colors.forEach(function (color) {
                    var colorHu19 = false;
                    var splitResults = MJ.splitColorCards(MJ.getValue(color, 1), MJ.getValue(color, MJ.COLOR_CARD_NUM), MJ.getColorCards(cards, color));
                    splitResults.forEach(function (result) {
                        var is19 = true;
                        result.forEach(function (item) {
                            var point = MJ.getPoint(item[0]);
                            if (item.length == 2) {
                                if (point != 1 && point != 9) {
                                    is19 = false;
                                }
                            } else if (item.length == 3) {
                                if (item[0] == item[1]) {
                                    if (point != 1 && point != 9) {
                                        is19 = false;
                                    }
                                } else {
                                    if (point != 1 && point != 7 && point != 9) {
                                        is19 = false;
                                    }
                                }
                            }
                        })

                        if (is19) {
                            colorHu19 = true;
                        }
                    });

                    if (!colorHu19) {
                        hu19 = false;
                    }
                });

                if (hu19) {
                    if (colors.length == 1) {
                        // 清幺九
                        pattern = Const.Pattern.QingYaoJiu;
                    } else {
                        // 幺九
                        pattern = Const.Pattern.DaiYaoJiu;
                    }
                }
            }

            if (pattern == Const.Pattern.PAIR
                || pattern == Const.Pattern.PAIR7
                || pattern == Const.Pattern.PAIR7_LONG) { //判断 将对

                var isJiangDui = true;

                this._pengCards.forEach(function(card) {
                    var point = MJ.getPoint(card);
                    if (point != 2 && point != 5 && point != 8) {
                        isJiangDui = false;
                    }
                });

                this._gangCards.forEach(function(gangInfo) {
                    var point = MJ.getPoint(gangInfo.card);
                    if (point != 2 && point != 5 && point != 8) {
                        isJiangDui = false;
                    }
                });

                if (isJiangDui) {
                    ExObject.eachKeyNum(cards, function(card, num) {
                        var point = MJ.getPoint(card);
                        if (point != 2 && point != 5 && point != 8) {
                            isJiangDui = false; return false;
                        }
                    });
                }

                if (isJiangDui) {
                    pattern = Const.Pattern.JiangDui;
                    // if (pattern == Const.Pattern.PAIR) {
                    //     pattern = Const.Pattern.JiangDui;
                    // } else if (pattern == Const.Pattern.PAIR7 || pattern == Const.Pattern.PAIR7_LONG) {
                    //     //pattern = Const.Pattern.JiangDui7;    // 没有将7对
                    //     pattern = Const.Pattern.JiangDui;
                    // }
                }
            }
        }

        return pattern;
    },
});